package com.project.service.goodsService.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.GoodsBean;
import com.project.bean.GoodsOrderBean;
import com.project.mapper.goodsMapper.IGoodsMapper;
import com.project.service.goodsService.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GoodsServiceImpl implements IGoodsService {
    @Autowired
    private IGoodsMapper goodsMapper;

    @Override
    public PageInfo<GoodsBean> findByItem(int pageNO, String goodsName, String type, String address, Integer storeId) {
        PageHelper.startPage(pageNO, PAGESIZE);
        return PageInfo.of(goodsMapper.findByItem(goodsName, type, address, storeId));
    }

    @Override
    public PageInfo<GoodsOrderBean> findByName(int pageNO, String goodsName, String type, String address, String storeName) {
        PageHelper.startPage(pageNO, PAGESIZE);
        return PageInfo.of(goodsMapper.findByName(goodsName, type, address, storeName));
    }


    @Override
    public GoodsBean findById(int goodsId) {
        return goodsMapper.findById(goodsId);
    }

    @Override
    public void add(GoodsBean goods, int storeId) {
        goodsMapper.add(goods, storeId);
    }


    @Override
    public void del(int goodsId) {
        goodsMapper.del(goodsId);
    }

    @Override
    public void update(int goodsId, int price) {
        goodsMapper.update(goodsId, price);
    }

    @Override
    public void updateNumber(int goodsId, int newNum) {
        goodsMapper.updateNumber(goodsId, newNum);
    }

    @Override
    public void delAllByStore(int storeId) {
        goodsMapper.delAllByStore(storeId);
    }


    @Override
    public void addAllByStore(int storeId) {
        goodsMapper.addAllByStore(storeId);
    }
}
